package com.common.result;

import lombok.Data;

import static com.common.exception.CustomExceptionType.*;


/**
 * @author 大忽悠
 */
@Data
public class Result {
    private Integer code;
    private String backMsg;
    private String frontMsg;
    private Object data;

    //-------------------成功-----------------------

    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setBackMsg(SUCCESS);
        result.setFrontMsg(SUCCESS);
        return result;
    }

    public static Result success(Object obj){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setBackMsg(SUCCESS);
        result.setFrontMsg(SUCCESS);
        result.setData(obj);
        return result;
    }

    public static Result success(String backMsg,String frontMsg,Object obj){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setBackMsg(backMsg);
        result.setFrontMsg(frontMsg);
        result.setData(obj);
        return result;
    }

    public static Result success(Integer code, String backMsg,String frontMsg, Object obj){
        Result result = new Result();
        result.setCode(code);
        result.setBackMsg(backMsg);
        result.setFrontMsg(frontMsg);
        result.setData(obj);
        return result;
    }

    //-------------------失败-----------------------

    public static Result error() {
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setBackMsg(INTERNAL_SERVER_ERROR);
        result.setFrontMsg(INTERNAL_SERVER_ERROR);
        return result;
    }

    public static Result error(String backErrMsg,String frontErrMsg) {
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setBackMsg(backErrMsg);
        result.setFrontMsg(frontErrMsg);
        return result;
    }

    public static Result error(Integer errorCode,String backErrMsg,String frontErrMsg) {
        Result result = new Result();
        result.setCode(errorCode);
        result.setBackMsg(backErrMsg);
        result.setFrontMsg(frontErrMsg);
        return result;
    }

}